/*
 * Author: Alberto De Pena
 * Applied Algorithms
 * mayan.cpp
 */

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void glyphOutPut( ofstream& fout, int glyph )
{
    if( glyph <= 5 )
    {
        switch( glyph )
        {
            case 0: fout << "@" << endl; 
				break;
            case 1: fout << "*" << endl; 
				break;
            case 2: fout << "**" << endl; 
				break;
            case 3: fout << "***" << endl; 
				break;
            case 4: fout << "****" << endl; 
				break;
            default: fout << "-----" << endl;  
				break;
        }
    }
    else
    {
        glyphOutPut( fout, glyph-5 );
        fout << "-----" << endl; 
    }
}

int number( int glyph1, int glyph2 = -1, int glyph3 = -1, int glyph4 = -1 )
{
    if( glyph4 > -1 )
        return 1 * glyph4 + 20 * glyph3 + 400 * glyph2 + 8000 * glyph1;
    else if( glyph3 > -1 )
        return 1 * glyph3 + 20 * glyph2 + 400 * glyph1;
    else if( glyph2 > -1 )
        return 1 * glyph2 + 20 * glyph1;
    else
        return 1 * glyph1;
}

void main()
{
    ifstream fin;
    ofstream fout;
    string line, operation;
    int glyph1, glyph2, glyph3, glyph4;
    bool glyphOne, glyphTwo, glyphThree, glyphFour;
    int numberOne, numberTwo, current, passes;

    fin.open( "mayan.in" );
    fout.open( "mayan.out" );

    getline( fin, line );

    while( line != "0" )
    {
        passes = 0;
        glyph1 = 0;
        glyph2 = 0;
        glyph3 = 0;
        glyph4 = 0;
        glyphOne = false; glyphTwo = false; glyphThree = false; glyphFour = false;

        while( line != "#" )
        {
            current = 0;
            while( line != "" && line != "#" )
            {
                if( line == "@" )
                    current += 0;
                else if( line == "*" )
                    current += 1;
                else if( line == "**" )
                    current += 2;
                else if( line == "***" )
                    current += 3;
                else if( line == "****" )
                    current += 4;
                else if( line == "-----" )
                    current += 5;

                getline( fin, line );
            }

            if( passes == 0 )
            {
                glyphFour = true;
                glyph4 = current;
            }
            else if( passes == 1 )
            {
                glyphThree = true;
                glyph3 = current;
            }
            else if( passes == 2 )
            {
                glyphTwo = true;
                glyph2 = current;
            }
            else
            {
                glyphOne = true;
                glyph1 = current;
            }
            passes++;
            if( line != "#" )
                getline( fin, line );
        }

        if( glyphOne )
            numberOne = number( glyph4, glyph3, glyph2, glyph1 );
        else if(glyphTwo)
            numberOne = number( glyph4, glyph3, glyph2 );
        else if(glyphThree)
            numberOne = number( glyph4, glyph3 );
        else
            numberOne = number( glyph4 );

        
        getline( fin, operation );
        getline( fin, line );

        passes = 0;
        glyph1 = 0;
        glyph2 = 0;
        glyph3 = 0;
        glyph4 = 0;
        glyphOne = false; glyphTwo = false; glyphThree = false; glyphFour = false;
		int answer, glyphNum;
		bool early = false;

        while( line != "#" )
        {
            current = 0;
            while( line != "" && line != "#" )
            {
                if( line == "@" )
                    current += 0;
                else if( line == "*" )
                    current += 1;
                else if( line == "**" )
                    current += 2;
                else if( line == "***" )
                    current += 3;
                else if( line == "****" )
                    current += 4;
                else if( line == "-----" )
                    current += 5;

                getline( fin, line );
            }
            if( passes == 0 )
            {
                glyphFour = true;
                glyph4 = current;
            }
            else if( passes == 1 )
            {
                glyphThree = true;
                glyph3 = current;
            }
            else if( passes == 2 )
            {
                glyphTwo = true;
                glyph2 = current;
            }
            else
            {
                glyphOne = true;
                glyph1 = current;
            }
            passes++;
            if( line != "#" )
                getline( fin, line );
        }

        if( glyphOne )
            numberTwo = number( glyph4, glyph3, glyph2, glyph1 );
        else if(glyphTwo)
            numberTwo = number( glyph4, glyph3, glyph2 );
        else if(glyphThree)
            numberTwo = number( glyph4, glyph3 );
        else
            numberTwo = number( glyph4 );

        
		if( operation == "+" )
			answer = numberOne + numberTwo;
		else
			answer = numberOne - numberTwo;

		if( answer / 160000 >= 1 )
		{
			glyphNum = answer / 160000;
			glyphOutPut( fout, glyphNum );
			answer = answer % 160000;
			if( answer == 0 )
				early = true;
			fout << endl;
		}
		if( early || answer / 8000 >= 1 )
		{
			glyphNum = answer / 8000;
			glyphOutPut( fout, glyphNum );
			answer = answer % 8000;
			if( answer == 0 )
				early = true;
			fout << endl;
		}
		if( early || answer / 400 >= 1 )
		{
			glyphNum = answer / 400;
			glyphOutPut( fout, glyphNum );
			answer = answer % 400;
			if( answer == 0 )
				early = true;
			fout << endl;
		}
		if( early || answer / 20 >= 1 )
		{
			glyphNum = answer / 20;
			glyphOutPut( fout, glyphNum );
			answer = answer % 20;
			fout << endl;
		}

    glyphNum = answer / 1;
    glyphOutPut( fout, glyphNum );
    fout << "#" << endl;

        getline( fin, line );
    }

    fin.close();
    fout.close();
}

